home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / mg2a_src.zip / SYS / AMIGA / ALLOCA.ASM next >
Assembly Source File  |  1988-08-23  |  985b  |  25 lines

  1. *
  2. * alloca()
  3. *
  4. * This routine was written by Stephen Walton, swalton@solar.stanford.edu,
  5. * a rank asm amateur, to attempt to provide the alloca() function for Manx
  6. * Aztec C on the Amiga.  It probably does horrible illegal things to the
  7. * stack but seems to mostly work.
  8. *
  9. * This subroutine expects a single int as argument, and returns a pointer
  10. * to a block of memory of that size allocated off the local stack.  Thus,
  11. * this memory is automatically freed when the current subroutine exits.
  12. *
  13. * This version for the default Manx settings (int = 16 bits).  To use
  14. * with int=32 bits, simply change both the ".w" to ".l"
  15. *
  16.     xdef    _alloca
  17. _alloca
  18.     move.l    a7,a1        ; Save current value of stack pointer
  19.     move.w    4(a7),d0    ; Number of bytes needed
  20.     suba.w    d0,a7        ; Move stack up that many places
  21.     move.l    (a1),(a7)    ; Place return address in proper place
  22.     move.l    a7,d0        ; Return value into d0
  23.     add.l    #6,d0        ;  plus amount by which stack is popped
  24.     rts            ; And back we go
  25.